package bocchi.power;

import bocchi.BocchiCore;
import bocchi.base.BaseCustomPower;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.cards.DamageInfo.DamageType;
import com.megacrit.cardcrawl.core.AbstractCreature;

public class ErosionPower extends BaseCustomPower {
    private static final String RAW_ID = "Erosion";
    public static final String GAME_ID = BocchiCore.getGameID(RAW_ID);

    public ErosionPower(AbstractCreature owner, int amount) {
        super(RAW_ID, PowerType.DEBUFF, owner, amount);
    }

    @Override
    public void updateDescription() {
        description = String.format(descriptions[0], amount);
    }

    @Override
    public int onAttacked(DamageInfo info, int damageAmount) {
        if (info.type == DamageType.NORMAL) {
            flash();
            addToTop(new DamageAction(owner, new DamageInfo(info.owner, amount, DamageType.HP_LOSS), AbstractGameAction.AttackEffect.POISON));
            addToTop(new ReducePowerAction(owner, info.owner, this, amount / 2 + 1));
        }

        return damageAmount;
    }

    @Override
    public void atStartOfTurn() {
        addToBot(new ReducePowerAction(owner, owner, this, amount));
    }
}
